/**
 * @(#) NovelAuthorsDao.java  
 *
 * @author lihg 
 * @version V1.0 2013-10-5  
 *
 * Copyright (C) 2010,2013 , Lihg
 */

/**
 * 
 */
package cn.com.dshome.acquisition.dao.novel;

import java.io.Serializable;
import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import cn.com.dshome.acquisition.dao.AbstractDao;
import cn.com.dshome.acquisition.entity.novel.NovelAuthors;

/**
 * 
 * Purpose:
 * 
 * @author lihg
 * @see
 * @since
 */
@Repository
public class NovelAuthorsDao extends AbstractDao<NovelAuthors> {

	public Serializable saveOrDoNothing(NovelAuthors author) {
		DetachedCriteria criteria = DetachedCriteria.forClass(NovelAuthors.class);
		criteria.add(Restrictions.eq("name", author.getName()));
		List<NovelAuthors> list = this.listByDetachedCriteria(criteria);
		if (null == list || list.size() == 0) {
			return this.save(author);
		} else {
			return list.get(0).getId();
		}
	}
}

/**
 * Revision history
 * -------------------------------------------------------------------------
 * 
 * Date Author Note
 * -------------------------------------------------------------------------
 * 2013-10-5 下午02:50:57 lihg 创建版本
 */
